<?php
require_once 'models/TMSTypeAggregateModel.inc';

/**
 * 
 * @author kras
 */
class TMSTypeOrderOptionsModel extends TMSTypeAggregateModel {
	
	/**
	 * returns name of list items class
	 *
	 * @return string
	 */
	public function ClassName(){
		return TMSTypeOrderOptionItem::GetClassName();
	}
	
	/**
	 * @return IPropertyMeta[]
	*/
	public function ClassProperties($object = null){
		return $this->TypesModel->OptionProperties();
	}
	
	protected function getAggregates(TMSTypeItem $type){
		return $type->OrderOptions;
	}
	protected function getAggregate(TMSTypeItem $type,$nm){
		return new TMSTypeOrderOptionItem($type->Base, $nm, $type->Base->OrderOptions[$nm], $this->TypesModel);
	}
	protected function getRawAggregates(TMSTypeItem $type){
		return $type->Base->OrderOptions;
	}
	protected function setRawAggregates(TMSTypeItem $type,$meta){
		$type->Base->OrderOptions = $meta;
	}
	protected function editData(TMSTypeItem $type){
		return array('Options'=>$type->Options);
	}
	
	/**
	 * @return IItem
	*/
	public function GetDummyItem($id = null, $class = null){
		return new TMSTypeOrderOptionItem($this->TypesModel->GetDummyItem()->Base, $id, (object)array(
					"Caption" => "",
					"Type" => "",
					"IsKitOption"=>false,
					"Selection" => ""
				), $this->TypesModel);
	}
	
	protected function parseData($nm,$data){
		$attr = array(
				'Name' => $nm,
				'Caption' => $data['Caption'],
				'Selection'=>$data['Selection']
		);
		
		if (isset($data['Type']))
			$attr['Type'] = $data['Type'];
		
		if (isset($data['IsKitOption']))
			$attr['IsKitOption'] = TConvertions::ConvertToBoolean($data['IsKitOption']);		

		if (isset($data['RefClass']))
			$attr['RefClass'] = $data['RefClass'];		
		
		return (object)$attr;
	}	
}